class Solution(object):
    def earliestFullBloom(self, plantTime, growTime):
        st = list(zip(growTime, plantTime))
        st.sort(reverse=True)
        last_grow = 0
        time = 0
        for g, p in st:
            if p >= last_grow:
                time += p - last_grow + g
                last_grow = g
            else:
                if last_grow - p >= g:
                    last_grow -= p
                else:
                    time += g - (last_grow - p)
                    last_grow = g
        return time
data = Solution()
plantTime = [1,4,3]
growTime = [2,3,1]
print(data.earliestFullBloom(plantTime, growTime))
plantTime = [1,2,3,2]
growTime = [2,1,2,1]
print(data.earliestFullBloom(plantTime, growTime))